package com.oa.dao.impl;

import java.io.Serializable;
import java.util.List;
import org.hibernate.SessionFactory;

import com.oa.dao.DeptDao;
import com.oa.entity.Dept;

public class DeptDaoImpl implements DeptDao {
	private SessionFactory sessionFactory;
	@Override
	public Integer saveDept(Dept dept) {
		Serializable id = sessionFactory.getCurrentSession().save(dept);
		return (Integer) id;
	}

	@Override
	public Integer deleteDept(Integer id) {
		sessionFactory.getCurrentSession().delete( findById(id) );
		return 1;
	}

	@Override
	public Dept findById(Integer id) {
		Dept dept  =sessionFactory.getCurrentSession()
				.get(Dept.class, id);
		return dept;
	}
	@Override
	public List<Dept> findAll() {
		String hql="from Dept";
		List<Dept> resultList = sessionFactory.getCurrentSession()
				          .createQuery(hql,Dept.class).getResultList();
		return resultList;
	}

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	

}
